Python DateTime add days to DateTime object

38

# Timedelta function demonstration
from datetime import datetime, timedelta

# Using current time
time_for_now = datetime.now()

# printing initial_date
print("initial_date", str(time_for_now))

# Calculating future dates
# for two years
future_date_after_1yr = time_for_now + timedelta(days=365)

future_date_after_5days = time_for_now + timedelta(days=5)

# printing calculated future_dates
print('future_date_after_1yr:', str(future_date_after_1yr))
print('future_date_after_5days:', str(future_date_after_5days))

Comments

Submit
0 Comments